package com.cyber.app_container.dto;

import com.cyber.app_container.exception.ErrorCode;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

@Data
@Builder
@JsonInclude(JsonInclude.Include.NON_NULL)
public class Response {
    private String code;
    private String message;
    private Object data;
    private Long recordsCount;
    private Integer pageNumber;
    private Integer pageSize;
    private Boolean success;

    public static Response success(Object data) {
        return Response.builder()
                .code(ErrorCode.SUCCESS.getCode())
                .message(ErrorCode.SUCCESS.getMessage())
                .data(data)
                .success(true)
                .build();
    }

    public static Response success(String message) {
        return Response.builder()
                .code(ErrorCode.SUCCESS.getCode())
                .message(message)
                .success(true)
                .build();
    }

    public static Response success(String message, Object data) {
        return Response.builder()
                .code(ErrorCode.SUCCESS.getCode())
                .message(message)
                .data(data)
                .success(true)
                .build();
    }

    public static Response success(PageInfo pageInfo, Object data) {
        return Response.builder()
                .code(ErrorCode.SUCCESS.getCode())
                .message(ErrorCode.SUCCESS.getMessage())
                .data(data)
                .recordsCount(pageInfo.getRecordsCount())
                .pageNumber(pageInfo.getPageNumber())
                .pageSize(pageInfo.getPageSize())
                .success(true)
                .build();
    }

    public static Response error(ErrorCode errorCode) {
        return Response.builder()
                .code(errorCode.getCode())
                .message(errorCode.getMessage())
                .success(false)
                .build();
    }

    public static Response error(String code, String message) {
        return Response.builder()
                .code(code)
                .message(message)
                .success(false)
                .build();
    }
}